const axios = require('axios')
// const Vue = require('vue')
const { Message } = require('element-ui');
const router = require('../../router/index');

module.exports = {
    namespaced: true,
    state: {
        cartData: [],
        pageData: {
            pageSize: 4,
            currentPage: 1,
        },
        search: {
            searchType: "",
            searchValue: ""
          },
    },
    mutations: {
        getRenCart(state, data) {
            state.cartData = data
            console.info("car",data)
        },
        changepageSize(state,size){
            state.pageData.pageSize = size;
        },
        changePage(state,page){
            state.pageData.currentPage = page
        },
    },
    actions: {
        async getcartsync(context,search) {
            // console.info("search",searchData)
            // if(context.state.search.searchType != "" && context.state.search.searchValue != ""){
            //     var searchData = context.state.searchData
            // }
            const searchData = context.state.search
            let fy = {
                pageSize: context.state.pageData.pageSize,
                currentPage: context.state.pageData.currentPage,
                ...searchData,
                search,
                status:"承租方"
            }
            const { data } = await axios.get("/users/getUsers", { params: fy});
            //使用mutations函数
            const ren = data
            console.info(ren)
            context.state.pageData.total = data.total;
            context.commit('getRenCart', ren);
        },
        async updatecartsync(context,_id) {
            let fy = {
                _id,
                status:"出租方"
            }
            const { data } = await axios.post("/users/uptateUsers",fy);
            //使用mutations函数
            const ren = data
            console.info(ren)
            context.dispatch('getcartsync', ren);
            console.info(ren)
        },



        handleCurrentChange(context, val) {
            context.state.pageData.currentPage = val
            context.dispatch('getcartsync')

        },
        handleSizeChange(context, val) {
            context.state.pageData.pageSize = val
            context.dispatch('getcartsync')
        },

    }

}